<%@ page import="com.lgx.right.entity.User" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();        //获取项目根节点
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>用户授权</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<jsp:include page="/page/head.jsp"></jsp:include>
	<script type="text/javascript">
		var userId = ${user != null?user.id:''};    //得到userid
		
		//加载系统中存在的全部角色
		$(document).ready(function(){
			var url =  path+'/role/userTree.do?t='+new Date().getTime()+"&userId="+userId;
			$('#perTree').tree({
				checkbox: true,
				url: url
			});
		});
		
		//保存编辑后的权限
		function save(){
			if($('#fm').form('validate')){
				var url =  path +"/user/updateRole.do?t="+new Date().getTime()+"&userId="+userId;
				var data = "&name="+escape(escape($('#name').val()));   //得到用户name 
				
				var nodes = $('#perTree').tree('getChecked');           //获取选中的信息
				var s = '';
				for(var i=0; i<nodes.length; i++){
					if (s != '') s += ',';                       	    //标示如果有多个，中间用 ， 隔开
					s += nodes[i].id;
				}
				
				data += "&ids="+s;
				
				$.ajax({
				  url: url,
				  data:data,
				  success: function(data) {
					   if(data == "1"){
						   window.location = path+"/user/userMgr.do";
					   }else{
						   alertBox("操作失败！");
					   }
				  }
				});
				
			}
		}
		
		function callback(){
			window.location = path+"/user/userMgr.do";
		}
	</script>
  </head>
  
  <body>
   <div class="right">
	<h1><b>用户授权</b><span><img src="<%=basePath%>images/right_h1bg2.jpg" width="3" height="29" /></span></h1>
	<form id="fm">
	<div class="ri_main">
		<table width="97%" border="0" cellspacing="1" cellpadding="8" style="background:#d9d9d9;">
		  <tr>
		    <td width="21%" align="right" bgcolor="#FFFFFF">名称：</td>
		    <td width="79%" bgcolor="#FFFFFF">
		      <input id="name" name="name" class="easyui-validatebox" required="true" style="width:200px;" value="${user != null?user.username:''}">
		    </td>
		  </tr>
		  <tr>
		    <td align="right" bgcolor="#FFFFFF">角色：</td>
		    <td bgcolor="#FFFFFF">
		    	<ul id="perTree" class="easyui-tree" checkbox="true" style="height:280px;border: 1;border-color:#99FF66">
				</ul>
		    </td>
		   </tr>
		   
		   <tr>
		    <td align="center" bgcolor="#FFFFFF" colspan="2">
				<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()">保存</a>
				<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-undo" onclick="callback()">取消</a>
			</td>
		   </tr>
		</table>
	</div>
	</form>
	</div>
  </body>
</html>
